﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = " Boms";
}
<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item ">ERP物料BOM添加</label>
            <ul id="lisul" class="row col-sm-4">
            </ul>
            <div class="anzhu col-sm-5" style="text-align:right">
                <div class="col-2">
                    <button id="tiJIa" class="btn-outline" type="submit">@Resource.String442</button>
                </div>
                @* <div class="col-2"><button id="CHAKAN" class="btn-outline" type="submit" style="width:70px;">@Resource.String443</button></div>*@
                <div class="col-2"><button class="btn-outline" id="tijiao" style="margin-left:25%">@Resource.String444</button></div>
                <div class="col-2"><button class="btn-outline" id="tiaoguo" style="margin-left:3%">@Resource.String445</button></div>
                <div class="col-2"><button class="btn-outline" id="btnreste">返回</button></div>
                @* <div class="col-2"><button id="log_back" class="btn-outline">@Resource.String491</button></div>*@
            </div>
        </div>
    </fieldset>
</from>
<div>
    <div>
        <div id="div1">
            <form class="biao1" action="/">
                <fieldset class="boun">
                    <legend class="len1 ">@Resource.String428</legend>
                    <table class="table" style="width:80%" align="left">
                        @foreach (LanDBom.Models.Applications item in Model)
                        {
                            <tr>
                                <td style="width:50%;">
                                    @Html.Label(Resource.String430):<label id="shenDan">@item.AP_bian</label>
                                </td>
                                <td>@Html.Label(Resource.String431): @item.App_qishi</td>
                            </tr>
                            <tr>
                                <td style="">
                                    @Html.Label("发起人")：<lable id="FQFQi">@item.AP_ren</lable>
                                </td>
                            </tr>
                            <tr style="display:none"><td id="jc_zhu">@(Session["JC_zhuang"])</td></tr>
                        }
                    </table>

                </fieldset>
            </form>
        </div>
    </div>

    <div>
        <button id="addwl" class="btn-outline">@Resource.String439</button>
        <button id="addw3" class="btn-outline">@Resource.String440</button>
        <button id="Shan" class="btn-outline">@Resource.String441</button>

        <select class="btn-outline" name="selop">
            @foreach (var item in ViewBag.fhishf as List<BOMini>)
            {
                <option value="@item.BOM2_BQing">@item.BOM2_wuLiu</option>
            }
        </select>

    </div>
    <div>
        <div style="display:none" id="JINDN">
            @*<lable id="XZ_S" style="color: blue; border-bottom: 1px solid blue; ">@Resource.String94</lable>*@
            <lable style="color: blue; border-bottom: 1px solid blue;" id="oneWu">@Resource.String95</lable>
        </div>
        <div style="display:none" id="Yin">
            @*<lable id="XZ_SZ" style="color: blue; border-bottom: 1px solid blue; ">@Resource.String94</lable>*@
            <lable style="color: blue; border-bottom: 1px solid blue;" id="Bomz">@Resource.String2000</lable>
        </div>
        <lable id="Biaos" style="display:none"></lable>
    </div>

    <div>
        <div class="tab1">
            <table id="Tenm" class="table table-sm">
                <thead class="table-light">
                    <tr style="text-align:center;">
                        <th style="width:50px;"><input type="checkbox" disabled="disabled" /></th>
                        <th scope="col">@Resource.String446</th>
                        <th scope="col">@Resource.String447</th>
                        <th scope="col">@Resource.String448</th>
                        <th scope="col">@Resource.Stringkh</th>
                        <th scope="col">@Resource.String449</th>
                        <th scope="col">@Resource.String99</th>
                        <th scope="col">@Resource.String450</th>
                        <th scope="col">@Resource.String451</th>
                        <th scope="col">@Resource.String452</th>
                        <th scope="col">@Resource.String453</th>
                        <th scope="col">@Resource.String454</th>
                        <th>@Resource.String455</th>
                        <th>@Resource.String456</th>
                        <th scope="col">@Resource.String457</th>
                    </tr>
                </thead>
                <tbody data-spy="scroll" id="BoTa">
                </tbody>
            </table>
        </div>
    </div>
    @*新建物料和料号*@
    <div id="addwl_main" style="display: none; position: absolute; border: 1px black solid; left: 20%; top: 30%; background-color: white; background-color: #f1f1f1">
        <div style="text-align: right; background-color: #84acde;" class="Tuodong">点击这里拖动窗体<span class="quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <table id="addwl_main_tab">
                <tr><td style="color:red">@Resource.String1261</td></tr>
                <tr>
                    <td>@Resource.String512<span style="color:red">*</span></td>
                    <td><input type="text" id="amt_WLM" class="amt_v" /></td>
                    <td>@Resource.String111</td>
                    @*料号*@
                    <td><input type="text" id="amt_WLBM" class="" readonly /></td>
                </tr>
                <tr>
                    <td>@Resource.String112</td>
                    <td><input type="number" id="amt_NYL" class="amt_v" /></td>
                    <td>@Resource.String113</td>
                    <td>
                        <input type="text" name="Biaomian" value="" readonly />
                        <div style="display:none" id="Yinchangs" class="Dingdiv">
                            <div style="display: flex; justify-content: space-between;"><span id="TanT">添加</span> <span><i class="bi bi-x-circle-fill quxiaoshi"></i></span></div>
                            <ul style="height:100px;overflow-y:scroll">
                                @foreach (var item in ViewBag.ZUI as List<jectsche>)
                                {
                                    <li><input type="checkbox" value="@item.Je_hanghao" class="Xuanz" />@item.Je_hanghao</li>
                                }
                            </ul>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>@Resource.String114</td>
                    <td><input type="text" id="amt_BMCL" class="amt_v" /></td>
                    <td>@Resource.String115</td>
                    <td><input type="text" id="amt_YCL" class="amt_v" /></td>
                </tr>
                <tr>
                    <td>@Resource.String116 <span style="color:red">*</span></td>
                    <td>
                        <select class="form-control" id="leibei_d" placeholder="">
                            <option value="0">请选择</option>
                            @foreach (var item in ViewBag.temp2 as List<buty3>)
                            {
                                <option value="@item.zl2_id">@item.zl2_name</option>
                            }
                        </select>
                    </td>
                    <td>@Resource.String120<span style="color:red">*</span></td>
                    <td>
                        <select class="form-control" id="leibei_x" placeholder="">
                            <option value="彩印纸箱">@Resource.String121</option>
                            <option value="水印拉链箱">@Resource.String1305</option>
                            <option value="水印瓦楞箱">@Resource.String1304</option>
                            <option value="瓦楞平板（规格≥500*250）">@Resource.String1306</option>
                            <option value="标签">@Resource.String1308</option>
                            <option value="说明书/卡片/折页">@Resource.String1309</option>
                            <option value="纸">@Resource.String1310</option>
                            <option value="纸护角">@Resource.String1311</option>
                            <option value="纸管">@Resource.String1312</option>
                            <option value="蜂窝制品">@Resource.String1313</option>
                            <option value="纸托盘">@Resource.String1314</option>
                            <option value="纸塑">@Resource.String1315</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>@Resource.String123 (mm)<span style="color:red">*</span></td>
                    <td><input type="number" class="amt_v guig" id="cahns" /></td>
                    <td>*<input type="number" class="amt_v guig" id="cahns1" /></td>
                    <td>*<input type="number" class="amt_v guig" id="cahns2" /></td>
                </tr>
                <tr>
                    <td>@Resource.String124</td>
                    <td><input type="text" id="amt_MS" class="amt_v" /></td>
                    <td>计量单位<span style="color:red">*</span></td>
                    <td>
                        <select id="amt_DW" style="width:100px;">
                            @foreach (var item in ViewBag.JIliang as List<Freht>)
                            {
                                <option value="@item.Fre_shijian">@item.Fre_beizhu</option>
                            }
                        </select>
                    </td>
                </tr>
                <tr><td>自制或外购</td><td><select id="shuxinss" style="width:100px;"><option value=""></option><option value="外购">外购</option><option value="自制">自制</option></select></td></tr>
            </table>
            <table class="table">
                <thead style="text-align:center;">
                    <tr style="background-color: #6e95bc">
                        <th>序号</th>
                        <th>文件名</th>
                        <th>料号</th>
                        <th>上传人</th>
                        <th>上传</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
                <tfoot>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </tfoot>
            </table>
        </div>
        <div style=" display: flex; justify-content: center;"><button id="queding">@Resource.String125</button>&emsp;&emsp;<button class="quxiao">@Resource.String126</button></div>
    </div>
</div>
<div id="WT_dh_mb" style="display:none;position:fixed;background-color:white;top:200px;width:660px;left:300px;z-index:1000;border:1px black solid;">
    <div id="WJ_ID" style="display:none"></div>
    <table>
        <tr>
            <td>@Resource.String501：</td>
            <td id="WT_dhr"></td>
        </tr>
        <tr>
            <td>请选择设计委托驳回到的节点</td>
            <td style="display:block" id="xianlw">
                <select id="WT_SJWt">
                    <option value="1">销售信息填写</option>
                    <option value="2">设计主管分配</option>
                    <option value="3">设计人员上传</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>@Resource.String502</td>
            <td><textarea id="WT_dhly"></textarea></td>
        </tr>
        <tr>
            <td id="WT_qdbh">@Resource.String503</td>
            <td id="WT_qxbh">@Resource.String504</td>
        </tr>
    </table>
</div>

@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>

        //实现页面显示BOM
        $(function () {
            CHANGEDF()
            $('select[name="selop"]').change(function () {
                CHANGEDF()
            })

            $("#addwl").click(function () {
                $("#JINDN").toggle()
                $("#Yin").hide()
            })
            $("#addw3").click(function () {
                $("#JINDN").hide()
                $("#Yin").toggle()
            })
            $(document).on("click", ".quxiao", function () {
                $("#addwl_main").css({ "display": "none" })
                $(".amt_v").val("")
            })
            $(document).on("click", "#btnreste", function () {
                window.location.href = "/Home/GYBOM";
            })
        })
        function CHANGEDF() {
            var shun = $('select[name="selop"] option:selected').val();
            var ghjd = $("#shenDan").text();
            $.ajax({
                url: "/Detailed/Boms",
                type: "POST",
                data: { "binaed": shun, "hudnf": ghjd, "state": 3 },
                success: function (sdf) {
                    creaBOM(sdf);
                },
                error: function () {
                    alert("erroer");
                },
            })
        };
        //BOM刷新
        function creaBOM(sdf) {
            $("#BoTa tr").remove();
            var sjng = $("#jc_zhu").text()
            console.log(sdf)
            var JIH = 0;
            if (sjng == "重新审核") {
                $.each(sdf, function (i, item) {
                    var temp7 = item.BOM2_Sone
                    JIH++;
                    var index = temp7 == "1" ? "纸制品" : temp7 == "2" ? "木制品" : temp7 == "3" ? "塑料制品" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                    if (item.BOM2_chen == "Leve0") {
                        $("#leb").text(item.BOM2_Guige)
                    }
                    var $tr = (`<tr id="WLtr">
                                    <td><input type="checkbox" name="trhang" disabled/></td>
                                    <td>${JIH}</td>
                                    <td style="display:none">${item.BOM2_id}</td>
                                    <td style="display:none">${item.Fo_id}</td>
                                    <td><input type="text" name="empShen" class="inwei" disabled="disabled" value="${item.BOM2_bian}"/></td>
                                    <td><label name="empChen" id="labes" >${item.BOM2_chen}</label></td>
                                    <td><input type="text" name="empkehu" class="inwei" value="${item.BOM2_duan}"/></td>
                                    <td style="width:200px;"><input type="text" id="empName" name="empName" class="inwei" list="seleect_codes" value="${item.BOM2_wuLiu}" />
                                    <datalist id="seleect_codes" class="form-control" style="display:none"></datalist></td>
                                    <td style="display:none"><input type="text" name="empLiap" value="${item.BOM2_liao}"/></td>
                                    <td><input type="text" name="empSun" class="inwei"value="${item.BOM2_Guige}"/></td>
                                    <td><input type="number" name="empNian" class="inwei"value="${item.BOM2_Nian}"/></td>
                                    <td><input type="number" name="empBom" class="inwei"value="${item.BOM2_Yong}"/></td>
                                        <td><input type="text" class="inwei" name="empSone" value="${index}"/></td>
                                        <td><input type="text" class="inwei" name="empSt" value="${item.BOM2_ST}"/></td>
                                    <td><input type="text" id="txtxun" class=" inwei" name="empLei" list="select_Lei" value="${item.BOM2_Lei}" />
                                            <datalist id="select_Lei" class="form-control" style="display:none">
                                            <option>--请选择--</option>
                                                <option value="外购">外购</option>
                                <option value="自制">自制</option>
                                            </datalist>
                                    </td>
                                    <td><input type="text" name="empTime" class="inwei" value="${item.BOM2_Ctime}" readonly/></td>
                                    <td><input id="delbom" type="button" class="inwei"value="删除" readonly title="从数据库中删除此条"/></td>
                                    <td><input type="text" name="empJie"class="inwei" value="${item.BOM2_fenzi}"/></td>
                                </tr>`);
                    $("#BoTa").append($tr);
                })
            } else {
                $.each(sdf, function (i, item) {
                    console.log(item)
                    JIH++;
                    var temp7 = item.BOM2_Sone
                    var index = temp7 == "1" ? "纸制品" : temp7 == "2" ? "木制品" : temp7 == "3" ? "塑料制品" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "" ? "套件" : temp7;
                    var $INP = "";
                    if (item.BOM2_chen == "Leve0") {
                        $("#leb").text(item.BOM2_Guige)
                        $INP = (`<input type="checkbox" name="trhang" disabled/>`)
                    } else {
                        $INP = (`<input type="checkbox" name="trhang" class="XANZK"/>`)
                    }
                    var $tr = (`<tr>
                                <td>${$INP}</td>
                                <td>${JIH}</td>
                                <td style="display:none">${item.BOM2_id}</td>
                                <td style="display:none">${item.Fo_id}</td>
                                <td><input type="text" class="inwei" name="empShen" value="${item.BOM2_bian}" readonly/></td>
                                <td><label name="empChen" id="labes" >${item.BOM2_chen}</label></td>
                                <td><input type="text" class="inwei" name="empkehu"  value="${item.BOM2_duan}"/></td>
                                <td style="width:200px;"><input type="text" class="inwei" id="empName" name="empName" value="${item.BOM2_wuLiu}"disabled style="background-color:#fff"/></td>
                                <td ><input type="text" name="empLiap" class="inwei"  value="${item.BOM2_liao}" disabled /></td>
                                <td><input type="text" class="inwei" name="empSun"value="${item.BOM2_Guige}" readonly/></td>
                                <td><input type="text" class="inwei" name="empNian" value="${item.BOM2_Nian}" readonly/></td>
                                <td><input type="text" class="inwei" name="empBom" value="${item.BOM2_Yong}" readonly/></td>
                                <td><input type="text" class="inwei" name="empSone" value="${index}" readonly/></td>
                                <td><input type="text" class="inwei" name="empSt" value="${item.BOM2_ST}" readonly/></td>
                                <td><input type="text"class="inwei" name="empLei" value="${item.BOM2_Lei}" readonly/></td>
                                <td><input type="text" class="inwei" name="empTime"  value="${item.BOM2_Ctime}" readonly/></td>
                                <td><input id="Updateed" type="button" class="inwei"value="修改" readonly title="修改该行物料"/></td>
                            </tr>`);
                    $("#BoTa").append($tr);
                })
            }
        }
        //新增行
        $(function () {
            //传值规则 层级
            function trAdd(CEJ) {
                //固定tr 行
                var len = $('#BoTa tr').length + 1;
                var shenDan = $("#shenDan").text();
                var now = new Date($.now());
                //获取当前年月日
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var qishi_time2 = year + "/" + month + "/" + date
                 var $tr = $(`<tr id="WLtr">
                                <td><input type="checkbox" name="trhang"class="XANZK"/></td>
                                <td>${len}</td>
                                <td><input type="text" name="empShen" class="inwei" disabled="disabled" value="${shenDan}"/></td>
                                <td><label name="empChen" id="labes" >${CEJ}</label></td>
                                <td><input type="text" name="empkehu" class="inwei"/></td>
                                <td style="width:200px;"><input type="text" id="empName" name="empName" class="inwei" list="seleect_codes" />
                                    <datalist id="seleect_codes" class="form-control" style="display:none"></datalist></td>
                                <td ><input type="text" class="inwei"  name="empLiap"/></td>
                                <td><input type="text" name="empSun" class="inwei"/></td>
                                <td><input type="number" name="empNian" class="inwei"/></td>
                                <td><input type="number" name="empBom" class="inwei"/></td>
                                <td ><input type="text" id="leibie" class="inwei" /></td>
                                <td id="jisndd"><input type="text" id="leib_ji" class="inwei" /> </td>
                                <td><input type="text" id="txtxun" class=" inwei" name="empLei" list="select_Lei" value="" />
                                    <datalist id="select_Lei" class="form-control" style="display:none">
                                        <option>--@Resource.String63--</option>
                                        <option value="外购">@Resource.String130</option>
                                        <option value="自制">@Resource.String131</option>
                                    </datalist>
                                </td>
                                <td><input type="text" name="empTime" class="inwei" readonly value="${qishi_time2}"/></td>
                                <td><input type="text" name="empBei" class="inwei"/ ></td>
                                <td style="display:none"><input type="text" name="empJie"class="inwei"/></td>
                                <td style="display:none">1</td>
                                <td style="display:none"></td>
                            </tr>`);
                $('#BoTa').append($tr);

            }
            $(document).on("click", "#oneWu", function () {
                var CEJ="leve1"
                trAdd(CEJ)
            })
            $(document).on("click", "#Bomz", function () {
                var CEJ = "leve2"
                trAdd(CEJ)
            })
        })

        //功能
        $(function () {
            //查看BOM
            $("#CHAKAN").click(function () {
                var bian = $("#shenDan").text();
                window.location.href = "/Detailed/BOMView?names=" + bian;
            })
            //提交功能
            $(document).on("click", "#tijiao,#tiaoguo", function () {
                if (confirm("是否已保存BOM")) {
                    var bian = $("#shenDan").text();
                    var SFJR = 3;
                    if (SFJR != 0) {
                        $.ajax({
                            url: "/Cuobaojia/Boms",
                            type: "POST",
                            data: { "binaed": bian, "state": 4 },
                            success: function (sdf) {
                                if (sdf == 0) {
                                    alert("提交失败！")
                                } else {
                                    alert("提交成功！")
                                    if (SFJR == 3) {
                                        window.location.href = "/Material/ERPGongy?names=" + bian;
                                    }
                                }
                            },
                            error: function () {
                                alert("erroer");
                            },
                        })
                    }
                }

            })
        })
        //物料搜索
        $(document).on("keyup", "input[name='empLiap']", function (x) {
            var shun = $(x.target).val();
            var Zhu = "10.01"
            var JHIK = 0;
            $(".XANZK").each(function (i, item) {
                var shunSED = $(item).parent().parent().children().eq(6).children().val()//物料编码
                if (shun == shunSED) {
                    JHIK++;
                }
            })
            if (JHIK > 1) {
                $(x.target).css({ "background": "red" })
            } else {
                $.ajax({
                    url: '/Cuobaojia/Application',
                    type: 'POST',
                    data: { "Named": shun, "Shunqi": Zhu, "state": 2 },
                    success: function (e) {
                        if (e.length > 0) {
                            $(x.target).css({ "background": "#ffffff" })
                            createSel(e);
                        } else {
                            $(x.target).css({ "background": "red" })
                        }
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            }
            function createSel(e) {
                $("#seleect_codes option").remove();
                var gui;
                var leix;
                var liao;
                var ji;
                var Sone = "";
                var SDET = "";
                var Nyleds = "";
                $.each(e, function (i, item) {
                    $("#seleect_codes").append(`<option value="${item.FM_name}">${item.FM_name}</option>`);
                    liao = item.FM_bai;
                    leix = item.FM_Zhuang
                    ji = item.FM_ji
                    gui = item.FM_gg
                    Sone = item.FM_yj == "纸制品" ? "纸质" : item.FM_yj == "木制品" ? "木质" : item.FM_yj == "塑料制品" || item.FM_ej == "胶带" ? "塑料" : item.FM_yj;
                    SDET = item.FM_ej
                    Nyleds = item.FM_nyl
                })
                $(x.target).parent().parent().children().eq(7).children().first().val(gui)
                $(x.target).parent().parent().children().eq(5).children().first().val(e[0].FM_name)
                $(x.target).parent().parent().children().eq(11).children().first().val(SDET)
                $(x.target).parent().parent().children().eq(12).children().first().val(leix)
                $(x.target).parent().parent().children().eq(15).children().first().val(ji)
                $(x.target).parent().parent().children().eq(10).children().first().val(Sone)
                $(x.target).parent().parent().children().eq(8).children().first().val(Nyleds)
            }
        })

        //批量添加BOM  添加BOM子级的标签
        $(function () {
            $("#tiJIa").click(function () {
                var BOMinise = [];
                var hang = $("#BoTa tr").length;
                var shen = $("#shenDan").text();
                var sun;
                var Bqing = $("select[name='selop'] option:selected").val()
                $("#BoTa tr").each(function (index, obj) {
                    var Lei = $("input[name='empLei']", obj).val();
                    if (Lei == "--请选择--") {
                        alert("请选择物料属性！");
                        sun = 1;
                        return;
                    }
                    var Sone = $("#leibie", obj).val() == null ? $("input[name='empSone']", obj).val() : $("#leibie", obj).val();
                    var Sted = $("#leib_ji", obj).val() == null ? $("input[name='empSt']", obj).val() : $("#leib_ji", obj).val();
                    Sone = Sone == "纸质" || Sone == "纸制品" ? "1" : Sone == "木质" || Sone == "木制品" ? "2" : Sone == "塑料" | Sone == "塑料制品" ? "3" : Sone == "金属制品" ? "4" : Sone == "布" ? "5" : Sone == "胶粘制品" ? "6" : Sone == "其他" ? "7" : Sone == "套件" ? "8" : Sone;
                    BOMinise.push({
                        BOM2_bian: $("input[name='empShen']", obj).val(),
                        BOM2_chen: $("#labes", obj).html(),
                        BOM2_wuLiu: $("input[name='empName'] ", obj).val(),
                        BOM2_liao: $('input[name="empLiap"]', obj).val(),
                        BOM2_duan: $("input[name='empkehu'] ", obj).val(),
                        BOM2_Nian: $("input[name='empNian'] ", obj).val(),
                        BOM2_Yong: $("input[name='empBom'] ", obj).val(),
                        BOM2_Lei: Lei,
                        BOM2_Ctime: $("input[name='empTime'] ", obj).val(),
                        BOM2_Guige: $("input[name='empSun'] ", obj).val(),
                        BOM2_mioa: $("input[name='empBei'] ", obj).val(),
                        BOM2_BQing: Bqing,
                        BOM2_fenzi: $('input[name="empJie"]', obj).val(),
                        BOM2_Sone: Sone,
                        BOM2_ST: Sted
                    })
                    console.log("共" + BOMinise.length + "数据");
                    console.log(BOMinise);
                })
                var appname = $("#shenDan").val();
                if (sun == 1) {
                    BOMinise = [];
                } else {
                    //发出请求
                    var shunf = $("#jc_zhu").text()
                    $.ajax({
                        url: "/Cuobaojia/AddAppli",
                        type: 'POST',
                        data: JSON.stringify(BOMinise),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            if (text > 0) {
                                alert("添加成功" + text.msg);
                                //window.location.href = "/Material/Index?names=" + shen;
                            } else {
                                alert("添加失败" + text.msg);
                            }
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })

                }

            })
        })

        //新增功能----切换+物料新增
        $(function () {
            //新增物料
            $(document).on("click", "#queding", function () {
                addwuliao()
            })
            //点击切换物料一级和二级类别
            $(document).on("change", "#leibei_d", function () {
                var Sone = $(this).val()
                $.ajax({
                    url: '/Admin/Purchasing_Authority',
                    type: 'GET',
                    data: { "id": Sone, "state": 4 },
                    success: function (data) {
                        console.log(data)
                        $("#leibei_x option").remove()
                        $.each(data, function (i, item) {
                            $("#leibei_x").append($(`<option value="${item.zl_name}">${item.zl_name}</option>`))
                        })
                    },
                    error: function () {
                        alert('Request Error2');
                    }
                })
            })

            //提交供应商的方法
            function addwuliao() {
                var dalie
                var temp7 = $('#leibei_d').val()
                dalie = temp7 == "1" ? "纸质" : temp7 == "2" ? "木质" : temp7 == "3" ? "塑料" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                var GUIGE = "";
                var intkom = $(".guig").length;
                var int = 1;
                $(".guig").each(function (i, gg) {
                    if (intkom > int) {
                        GUIGE += $(gg).val() + "*"
                    } else {
                        GUIGE += $(gg).val()
                    }
                    int++;
                })
                var application = {
                    FM_bai: $("#amt_WLBM").val(),
                    FM_name: $("#amt_WLM").val(),
                    FM_nyl: $('#amt_NYL').val(),
                    FM_zx: $('#txtqishi').val(),
                    FM_yj: dalie,
                    FM_ej: $('#leibei_x').val(),
                    FM_bmcl: $('#amt_BMCL').val(),
                    FM_ycl: $('#amt_YCL').val(),
                    FM_ms: $('#amt_MS').val(),
                    FM_gg: GUIGE,
                    FM_ji: $("#amt_DW").val(),
                    FM_long: $("#cahns").val(),
                    FM_kuan: $("#cahns1").val(),
                    FM_gao: $("#cahns2").val(),
                    FM_Jieti: $("input[name='Biaomian']").val(),
                    FM_Zhuang: $("#shuxinss").val()
                };
                //bom heding
                console.log(application)
                if (application.FM_name != "" && application.FM_ej != "" && application.FM_ej != "" && application.FM_gg != "") {
                    if (application.FM_long == "" && application.FM_kuan == "" && application.FM_gao == "") {
                        alert("规格数据不符合要求")
                        return
                    }
                    if (application.FM_Jieti == "") {
                        alert("最小起订量需要选择")
                        return
                    }
                    if (application.FM_Zhuang == "") {
                        alert("物料需要选择自制或外购")
                        return
                    }
                    $.ajax({
                        url: "/Application/Addfor",
                        type: "POST",
                        data: { "applications": application, "names": $("#shenDan").text() },
                        success: function (data) {
                            if (data == "修改成功") {
                                alert(data)
                                CHANGEDF()
                            } else if (data == "修改失败") {
                                alert(data)
                            } else {
                                AppendBOMLine()
                            }
                            $("#addwl_main").css({ "display": "none" })
                            $(".amt_v").val("")
                        },
                        error: function () {
                            alert("erroer");
                        },
                    })
                } else {
                    alert("请输入必须字段")
                }
            }
            //增加BOM行
            function AppendBOMLine() {
                var GUIGE = "";
                var intkom = $(".guig").length;
                var int = 1;
                $(".guig").each(function (i, gg) {
                    if (intkom > int) {
                        GUIGE += $(gg).val() + "*"
                    } else {
                        GUIGE += $(gg).val()
                    }
                    int++;
                })
                var temp1 = $("#amt_WLM").val()
                var temp2 = $("#amt_NYL").val()
                var temp3 = $("#amt_BMCL").val()
                var temp4 = $("#amt_YCL").val()
                var temp5 = $("#amt_GG").val()
                var temp6 = $("#amt_MS").val()
                var temp7 = $("#leibei_d").val()
                var temp9 = $("#leibei_x").val()
                var temp10 = $("#amt_DW").val()
                var temp11 = $("#shuxinss").val()
                var temp12 = $("#amt_WLBM").val()
                var temp8 = "";
                if ($("#Biaos").text() == 1) {
                    temp8 = "leve1"
                } else {
                    temp8 = "leve2"
                }
                temp7 = temp7 == "1" ? "纸制品" : temp7 == "2" ? "木制品" : temp7 == "3" ? "塑料制品" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8"?"套件": temp7;
                var $tr = $(`<tr id="WLtr">
		                        <td><input type="checkbox" /></td>
		                        <td></td>
		                        <td><input type="text" name="empShen" class="inwei" readonly /></td>
		                        <td><label name="empChen" id="labes">${temp8}</label></td>
		                        <td><input type="text" name="empkehu" class="inwei"/></td>
		                        <td style="width:200px;"><input type="text" id="empName" name="empName" class="inwei" value="${temp1}" /></td>
		                        <td ><input type="text" class="inwei"  name="empLiap" value="${temp12}"/></td>
		                        <td><input type="text" name="empSun" class="inwei" value="${GUIGE}" /></td>
		                        <td><input type="number" name="empNian" class="inwei" value="${temp2}" /></td>
		                        <datalist id="select_codes" class="form-control" style="display:none">
			                        @foreach (var item in ViewBag.JIliang as List<Freht>)
				                        {
				                        <option>@item.Fre_beizhu</option>
				                        }
		                        </datalist></td>
		                        <td><input type="number" name="empBom" class="inwei" /></td>
		                        <td><input type="text" name="empSone" class="inwei" value="${temp7}" /></td>
		                        <td id="jisndd"> <input type="text" class="inwei" name="empSt" list="select_codes" value="${temp9}" /></td>
		                        <td>
			                        <input type="text" id="txtxun" class=" inwei" name="empLei" list="select_Lei" value="${temp11}" />
			                        <datalist id="select_Lei" class="form-control" style="display:none">
				                        <option>--@Resource.String63--</option>
				                        <option value="外购">@Resource.String130</option>
				                        <option value="自制">@Resource.String131</option>
			                        </datalist>
		                        </td>
		                        <td><input type="text" name="empTime" class="inwei" readonly="readonly" /></td>
		                        <td><input type="text" name="empBei" class="inwei" /></td>
		                        <td style="display:none"><input type="text" name="empJie" class="inwei" value="${temp10}" /></td>
		                        <td style="display:none">0
		                        <td>
	                        </tr>`);
                $('#BoTa').append($tr);
                var shenDan = $("#shenDan").text();//获取申请编号
                $("input[name='empShen']").val(shenDan);
                var now = new Date($.now());
                //获取当前年月日
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var qishi_time2 = year + "/" + month + "/" + date
                $("input[name='empTime']").val(qishi_time2);
                $("input,select").attr({ "autocomplete": "off" })
                //添加序号
                var len = $('#BoTa tr').length;
                for (var i = 0; i < len; i++) {
                    $('#BoTa tr:eq(' + i + ') td:nth-child(2)').text(i + 1);
                }
            }
            //查看物料信息
            $(document).on("click", "#A_WLXX", function (e) {
                getMaterialInformation($(e.target))
            })
            //表面
            $('input[name="Biaomian"]').click(function () {
                $("#Yinchangs").toggle();
            })
            $('.quxiaoshi').click(function () {
                $("#Yinchangs").toggle();
            })

            //点击确定按钮//表面
            $(document).on("change", ".Xuanz", function () {
                $('input[name="Biaomian"]').val("")
                $("#Yinchangs").find("input[type='checkbox']").each(function () {
                    if ($(this).prop("checked")) {
                        $('input[name="Biaomian"]').val($('input[name="Biaomian"]').val() + ($('input[name="Biaomian"]').val() == "" ? "" : ",") + $(this).val())
                        $(this).prop('checked', true)
                        $(this).prop('disabled', false)
                    }
                });
            })
            //获取物料信息
            function getMaterialInformation(e) {
                var temp = e.parent().parent().children().eq(3).text()
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": temp, "state": 6 },
                    success: function (sjik) {
                        $.each(sjik, function (i, item) {
                            $("#amt_WLM").val(item.FM_name)
                            $("#amt_NYL").val(item.FM_nyl)
                            $("#amt_BMCL").val(item.FM_bmcl)
                            $("#amt_YCL").val(item.FM_ycl)
                            $("#amt_GG").val(item.FM_gg)
                            $("#amt_MS").val(item.FM_ms)
                            $("#leibei_d").val(item.FM_nyl)
                            $("#leibei_x").val(item.FM_nyl)
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }

        })
        //新增和删除物料行
        $(function () {
            //删除物料行
            $("#Shan").click(function () {
                if (confirm('确定要删除这些物料吗?')) {
                    Tboms()
                }
            })
            function Tboms() {
                var formation = [];
                $("input[class='XANZK']:checked").each(function (index, obj) {
                    console.log($(obj).parent().parent().children().eq(2).text())
                    var shunnn = $(obj).parent().parent().children().eq(2).text()
                    if (shunnn != "") {
                        formation.push({
                            FM_bai: shunnn,
                            FM_name: $("#txtdan").val(),
                        })
                    } else {
                        $(obj).parent().parent().remove()
                    }
                })
                console.log("共" + formation.length + "数据");
                console.log(formation);
                if (formation.length > 0) {
                    $.ajax({
                        url: "/Application/RemoveMaterial",
                        type: "POST",
                        data: JSON.stringify(formation),
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        success: function (text) {
                            $("input[class='XANZK']:checked").parent().parent().remove();
                        },
                        error: function () {
                            $("input[class='XANZK']:checked").parent().parent().remove();
                            console.log("系统错误");
                        }
                    })
                }
            }
        })
        $(function () {

            $(document).on("click", "#Updateed", function (e) {
                getMaterialInformation($(e.target))
            })
            //获取物料信息
            function getMaterialInformation(e) {
                var temp = e.parent().parent().children().eq(8).children().val()//料号
                var temp2 = temp
                console.log(temp2)
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "Name": temp2, "state": 16 },
                    success: function (sjik) {
                        console.log(sjik)
                        $.each(sjik, function (i, item) {
                            $("#amt_WLM").val(item.FM_name)
                            $("#amt_WLBM").val(item.FM_bai)
                            $("#cahns").val(item.FM_long)
                            $("#cahns1").val(item.FM_kuan)
                            $("#cahns2").val(item.FM_gao)
                            $("#amt_BMCL").val(item.FM_bmcl)
                            $("#amt_YCL").val(item.FM_ycl)
                            $("#amt_MS").val(item.FM_ms)
                            $("#Biaomian").val(item.FM_zx)
                            $("#amt_NYL").val(item.FM_nyl)
                            $("#amt_DW").val(item.FM_ji)
                            $("#shuxinss").val(item.FM_Zhuang)
                            $("input[name='Biaomian']").val(item.FM_Jieti)
                            var Sone = item.FM_yj;
                            Sone = Sone == "纸质" || Sone == "纸制品" ? "1" : Sone == "木制品" || Sone == "木质" ? "2" : Sone == "塑料制品" || Sone == "塑料" ? "3" : Sone == "金属制品" ? "4" : Sone == "布" ? "5" : Sone == "胶粘制品" ? "6" : Sone == "其他" ? "7" : Sone;
                            $("#leibei_d").val(Sone)
                            //var akom = $("#leibei_d").parent().next().children().get()
                            $.ajax({
                                url: '/Admin/Purchasing_Authority',
                                type: 'GET',
                                data: { "id": Sone, "state": 4 },
                                success: function (data) {
                                    console.log(data)
                                    $("#leibei_x option").remove()
                                    $.each(data, function (i, item) {
                                        $("#leibei_x").append($(`<option value="${item.zl_name}">${item.zl_name}</option>`))
                                    })
                                },
                                error: function () {
                                    alert('Request Error2');
                                }
                            })
                            $("#leibei_x").val(item.FM_ej)
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
                $("#addwl_main").css({ "display": "block" })
                $("#amt_WLM").attr({ "readonly": "readonly" })
                if ($("#Login_bm").text() == "设计") {
                    $("#queding").css({ "display": "none" })
                }
            }
        })

    </script>
}